/**  
* @Title:  SysConfigForm.java
* @Package com.colldown.iservice.sysconfig.web.impl
* @Description: TODO(用一句话描述该文件做什么)
* @author Wayne
* @date  2015-5-23 下午2:22:37
* @version V1.0  
* Update Logs:
* ****************************************************
* Name:
* Date:
* Description:
******************************************************
*/
package com.colldown.iservice.sysconfig.web.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.colldown.common.A_Tools;
import com.colldown.iservice.sysconfig.service.ISysConfigService;
import com.colldown.iservice.sysconfig.web.ISysConfigForm;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * @ClassName: SysConfigForm
 * @Description: TODO(系统设置业务类)
 * @author Wayne
 * @date 2015-5-23 下午2:22:37
 *
 */
@Controller
@RequestMapping("/SysConfigForm")
public class SysConfigFormImpl implements ISysConfigForm {
	@Autowired
	ISysConfigService sysConfigService;

	@Override
	@RequestMapping("/deviceConfigDetail")
	public String deviceConfigDetail(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String Station_ID =A_Tools.NullToStr(request.getParameter("STATION_ID"));
		//参数集合
		Map paramMap = new HashMap();
		paramMap.put("STATION_ID",Station_ID );
		Map deviceMap = this.sysConfigService.queryDeviceConfigById(paramMap);
		deviceMap.put("STATION_NAME", new String((byte[])deviceMap.get("STATION_NAME")).trim());
		model.addAttribute("device", deviceMap);
		return "deviceDetail";
	}
	
	@Override
	@RequestMapping("/deviceConfigEdit")
	public String deviceConfigEdit(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String Station_ID =A_Tools.NullToStr(request.getParameter("STATION_ID"));
		//参数集合
		Map paramMap = new HashMap();
		paramMap.put("STATION_ID",Station_ID );
		Map deviceMap = this.sysConfigService.queryDeviceConfigById(paramMap);
		deviceMap.put("STATION_NAME", new String((byte[])deviceMap.get("STATION_NAME")).trim());
		model.addAttribute("device", deviceMap);
		return "deviceEdit";
	}
	
	@Override
	@RequestMapping("/deviceConfigEditSave")
	public void deviceConfigEditSave(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String formObj="";
		try {
			//获取form表单
			formObj = URLDecoder.decode(A_Tools.NullToStr(request.getParameter("formObj")),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Gson gson = new Gson();
		//将json格式的form表单转化为map
		Map paramMap = gson.fromJson(formObj, Map.class);
		paramMap.put("STATION_NAME", paramMap.get("STATION_NAME").toString().getBytes());
		int rst = this.sysConfigService.updDeviceConfigById(paramMap);
		A_Tools.printJson(response, rst+"");
		
	}

	@Override
	@RequestMapping("/netDeviceConfigDetail")
	public String netDeviceConfigDetail(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String Eth_ID =A_Tools.NullToStr(request.getParameter("ETH_ID"));
		//参数集合
		Map paramMap = new HashMap();
		paramMap.put("ETH_ID",Eth_ID );
		Map deviceMap = this.sysConfigService.queryNetDeviceConfigById(paramMap);
		deviceMap.put("ETH_NAME", new String((byte[])deviceMap.get("ETH_NAME")).trim());
		model.addAttribute("device", deviceMap);
		return "netDeviceDetail";
	}
	
	@Override
	@RequestMapping("/netDeviceConfigEdit")
	public String netDeviceConfigEdit(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String Eth_ID =A_Tools.NullToStr(request.getParameter("ETH_ID"));
		//参数集合
		Map paramMap = new HashMap();
		paramMap.put("ETH_ID",Eth_ID );
		Map deviceMap = this.sysConfigService.queryNetDeviceConfigById(paramMap);
		deviceMap.put("ETH_NAME", new String((byte[])deviceMap.get("ETH_NAME")).trim());
		model.addAttribute("device", deviceMap);
		return "netDeviceEdit";
	}
	
	@Override
	@RequestMapping("/netDeviceConfigEditSave")
	public void netDeviceConfigEditSave(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String formObj="";
		try {
			//获取form表单
			formObj = URLDecoder.decode(A_Tools.NullToStr(request.getParameter("formObj")),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Gson gson = new Gson();
		//将json格式的form表单转化为map
		Map paramMap = gson.fromJson(formObj, Map.class);
		paramMap.put("ETH_NAME", paramMap.get("ETH_NAME").toString().getBytes());
		int rst = this.sysConfigService.updNetDeviceConfigById(paramMap);
		A_Tools.printJson(response, rst+"");
		
	}



}
